/*
 * http_c3.h
 *
 *  Created on: Dec 11, 2013
 *      Author: killerg
 */

#ifndef HTTP_C3_H_
#define HTTP_C3_H_

#include <string>
#include <stack>
#include <functional>

#include <curl/curl.h>
#include <uv.h>

class http_client3;
struct curl_context_t {
  uv_poll_t poll_handle;
  curl_socket_t sockfd;
  http_client3* client;
};

struct my_timer_t {
  uv_timer_t timer;
  http_client3* client;
};



class http_client3 {

    public:
        typedef std::function<void(CURLcode, const std::string&)> client_cb_t;

        bool do_query(const char* url, const char* body, client_cb_t cb = NULL);

        bool init();
        void destroy();
        void update();

        int pending_num() { return still_running; }

    public:
        int still_running;
        uv_loop_t *loop;
        CURLM *curl_handle;
        my_timer_t timeout;
        std::stack<CURL*> free_handles;
};


#endif /* HTTP_C3_H_ */
